﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.GData.Spreadsheets;

namespace GoogleFeeder
{
    public class CellAddress : Tuple<uint, uint>
    {
        public CellAddress(uint col, uint row)
            : base(col, row)
        {
        }

        public uint Col
        {
            get
            {
                return this.Item1;
            }
        }

        public uint Row
        {
            get
            {
                return this.Item2;
            }
        }

        public string IdString
        {
            get
            {
                return string.Format("R{0}C{1}", Row, Col);
            }
        }
    }
    
    public class CellBag
    {
        public readonly Worksheet Parent;
        public readonly Dictionary<CellAddress, Cell> Cells;

        public CellBag(Worksheet parent)
        {
            Parent = parent;
            Cells = new Dictionary<CellAddress, Cell>();
        }

        public void Add(uint col, uint row, CellEntry theCell)
        {
            Cells[new CellAddress(col, row)] = new Cell(Parent, theCell);
        }

        public Cell this[uint col, uint row]
        {
            get
            {
                CellAddress addr = new CellAddress(col, row);
                return this[addr];
            }
        }

        public Cell this[CellAddress addr]
        {
            get
            {
                if (!Cells.ContainsKey(addr))
                    return null;
                return Cells[addr];
            }
        }
    }
}
